<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/1/14
 * Time: 16:04
 */

namespace app\wechat\controller\v1;
use wechat\WXBizDataCrypt;

class User
{
    public function login(){
        $params = input("post.");

        //微信调用登录接口
        $loginAPI = 'https://api.weixin.qq.com/sns/jscode2session?appid=自己填写&secret=自己填写&js_code='.$params['code'].'&grant_type=authorization_code';
        $result = file_get_contents($loginAPI);
        $json = json_decode($result);
         return $json;
    }

    public function decodeData(){
        $appid = 'wxdab92116dd54d35b';//定义的小程序的appid
        $params = input("post.");

        $pc = new WXBizDataCrypt($appid, $params['sessionKey']);
        $errCode = $pc->decryptData($params['encryptedData'], $params['iv'], $data );
        if($errCode == 0){
            return json_decode($data);
        }
        return $errCode;
    }
}